package com.leetCode.easy;

/**
 * 给你一个数组 nums ，数组中有 2n 个元素，按 [x1,x2,...,xn,y1,y2,...,yn] 的格式排列。
 * 请你将数组按 [x1,y1,x2,y2,...,xn,yn] 格式重新排列，返回重排后的数组
 */
public class ResetNums {

    public static void main(String[] args) {
        int[] nums = {2, 5, 1, 3, 4, 7};
        int[] ints = shuffle(nums, 3);
        for (int num : nums) {
            System.out.print(num + "  ");
        }
        System.out.println();
        for (int anInt : ints) {
            System.out.print(anInt + "  ");
        }
    }


    public static int[] shuffle(int[] nums, int n) {
        //先定义一个同长度的数组
        int[] newNums = new int[nums.length];
        int j = n;
        int k = 0;
        for (int i = 0; i < nums.length; i++) {
            if (j < nums.length) {
                newNums[i] = nums[k++];
                newNums[i + 1] = nums[j];
                j++;
                i++;
            }
        }
        return newNums;
    }
}
